//队伍信息的小仓库 =》队伍的推荐信息列表 + 创建的队伍信息 +  加入的队伍信息
// 引入defineStore用于创建store
import {defineStore} from 'pinia'
import {getTeamCreate, getTeamInfoAndSearch, getTeamJoin} from "../../api/teamApi.ts";


// 定义并暴露一个store(最好就是再redis缓存,因为我们修改或者解散队伍，就会影响其他用户的结果！) todo
export const teamStore = defineStore('Team',{
    // 动作
    actions:{
        getTeamRecommendList(data){
            //获取队伍信息
            getTeamInfoAndSearch(data).then(res =>{
                if (res.code == 200){
                    this.teamRecommendList =  res.data;//公共仓库存储信息
                }
            }).catch(error =>{
                console.log(error);
            });
        },
        getTeamCreatedList(){
            //获取创建的队伍信息
            getTeamCreate().then(res =>{
                if (res.code == 200){
                    this.teamCreateList = res.data;//公共仓库存储信息
                }
            }).catch(error =>{
                console.log(error);
            });

        },
        getTeamJoinList(){
            //获取用户加入的队伍信息
            getTeamJoin().then(res =>{
                if (res.code == 200){
                    this.teamJoinList = res.data;//公共仓库存储信息
                }
            }).catch(error =>{
                console.log(error);
            });
        },

        setTeamRecommendList(data:[]){
            this.teamRecommendList = data;
        },
        setTeamCreateList(data){
            this.teamCreateList = data;
        },
        setTeamJoinList(data){
            this.teamJoinList = data;
        }
    },
    // 状态
    state(){
        return {
            //队伍的推荐信息列表
            teamRecommendList: [],
            teamCreateList: [],
            teamJoinList: []
        }
    },
    // 计算
    getters:{}
})
